package com.deer.wms.lzb.erp.web;

import com.deer.wms.lzb.erp.model.ErpRecord;
import com.deer.wms.lzb.erp.model.ErpRecordCriteria;
import com.deer.wms.lzb.erp.service.ErpRecordService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.deer.wms.project.root.core.result.Result;
import com.deer.wms.project.root.core.result.ResultGenerator;

import java.util.List;

/**
* Created by  on 2021/02/14.
*/
@RestController
@RequestMapping("/erp/records")
public class ErpRecordController {

    @Autowired
    private ErpRecordService erpRecordService;

    @PostMapping("/add")
    public Result add(@RequestBody ErpRecord erpRecord) {
        erpRecordService.save(erpRecord);
        return ResultGenerator.genSuccessResult();
    }

    @GetMapping("/delete")
    public Result delete(  Integer id) {
        erpRecordService.removeById(id);
        return ResultGenerator.genSuccessResult();
    }

    @PostMapping("/update")
    public Result update(@RequestBody ErpRecord erpRecord) {
        erpRecordService.updateById(erpRecord);
        return ResultGenerator.genSuccessResult();
    }

    @GetMapping("/{id}")
    public Result detail(@PathVariable Integer id) {
        ErpRecord erpRecord = erpRecordService.getById(id);
        return ResultGenerator.genSuccessResult(erpRecord);
    }

    @GetMapping("/list")
    public Result list(ErpRecordCriteria criteria) {
        PageHelper.startPage(criteria.getPageNum(), criteria.getPageSize());
        List<ErpRecord> list = erpRecordService.findList(criteria);
        PageInfo pageInfo = new PageInfo(list);
        return ResultGenerator.genSuccessResult(pageInfo);
    }

}
